<template>
  <div class="personal">
    <!-- 头部头像 -->
    <router-link to="/edit_profile">
      <div class="profile">
        <!-- 使用过滤器拼接没有基础路径的路径 -->
        <img :src="userInfo.head_img | joinPath" alt />
        <div class="profile-center">
          <div class="name">
            <span
              class="iconfont pink"
              :class="{
                iconxingbienan: userInfo.gender === 1,
                iconxingbienv: userInfo.gender === 0,
              }"
            ></span
            >{{ userInfo.nickname }}
          </div>
          <div class="time">{{ userInfo.create_date | FormDay }}</div>
        </div>
        <span class="iconfont iconjiantou1"></span>
      </div>
    </router-link>
    <!-- 内容 -->
    <div class="content">
      <van-cell title="我的关注" is-link value="关注的用户" />
      <van-cell title="我的跟贴" is-link value="跟贴/回复" />
      <van-cell title="我的收藏" is-link value="文章/视频" />
      <van-cell title="设置" is-link />
    </div>
    <!-- 退出按钮 -->
    <van-button color="#eb6112" round type="primary" block @click="singnOutFn"
      >退出</van-button
    >
  </div>
</template>

<script>
import { userInfo } from "../api/user";
export default {
  data() {
    return {
      userInfo: {},
    };
  },
  //   获取用户信息，并保存该对象，渲染到结构上
  created() {
    let id = localStorage.getItem("my-hm-id");
    // 接口地址：/user/:id  这里的id表示前端需要传递给后端的参数
    //如何传递呢？答：直接把id拼接到user后面，比如：用户id是12
    //代码如何："/user/"+id === 渲染出来就是 /user/12
    userInfo(id).then((res) => {
      this.userInfo = res.data.data;
      console.log(43, res);
    });
  },
  //   退出功能
  methods: {
    singnOutFn() {
      // 清除缓存的token和id
      localStorage.removeItem("my-hm-token");
      localStorage.removeItem("my-hm-id");
      //   跳转到登录页面
      this.$router.push("/login");
    },
  },
};
</script>

<style lang="less" scoped>
.van-cell {
  background-color: #eee;
  border: 1px solid #dddddd;
}
.van-button {
  width: 90%;
  margin: 20px auto;
}
.personal {
  width: 100vw;
  height: 100vh;
  background-color: #eee;
}
a {
  color: #666;
}
.profile {
  display: flex;
  padding: 20px 10px;
  justify-content: space-between;
  align-items: center;
  border-bottom: 5px #ddd solid;

  img {
    width: (70 / 360) * 100vw;
    height: (70 / 360) * 100vw;
    border-radius: 50%;
  }

  .profile-center {
    flex: 1;
    padding: 0 10px;
  }

  .name {
    span {
      color: #75b9eb;
    }
  }

  .time {
    color: #666;
    font-size: 14px;
    margin-top: 5px;
  }
}
</style>